//
//  PlayerViewController.m
//  CoolFM
//
//  Created by 曹曹 on 16/9/12.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "PlayerViewController.h"
#import "CFMacro.h"
#import "PlayerCollectionViewCell.h"
#import "PlayerDetailCollectionViewCell.h"
#import "UINavigationController+FDFullscreenPopGesture.h"
#import "UIView+Frame.h"
#import "AlbumRecord_Plays.h"
#import "AlbumRecord.h"
#import "GXNetTool.h"
#import "UIImageView+WebCache.h"

#define kPlayerCollectionViewCell @"PlayerCollectionViewCell"
#define kPlayerDetailCollectionViewCell @"PlayerDetailCollectionViewCell"

@interface PlayerViewController () <UICollectionViewDelegate, UICollectionViewDataSource, UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *layout;
@property (weak, nonatomic) IBOutlet UILabel *pageTitle;

@end

@implementation PlayerViewController

#warning PlayerViewController send noti
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    // 不使用宏定义, 因为宏定义不能全局搜索, 只能当前页面搜索到, 定位不到位置, 不方便
    [[NSNotificationCenter defaultCenter] postNotificationName:@"hidePlayerView"
                                                        object:@"playerView"
                                                      userInfo:nil];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"showCommentBar"
                                                        object:@"commentBar"
                                                      userInfo:nil];
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"hideCommentBar"
                                                        object:@"commentBar"
                                                      userInfo:nil];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"showPlayerView"
                                                        object:@"playerView"
                                                      userInfo:nil];
}
#pragma mark - model setter
- (void)setRecord_plays:(AlbumRecord_Plays *)record_plays {
    _record_plays = record_plays;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    _pageTitle.text = _record_plays.record_play_name;
    [self handleData];
    self.fd_prefersNavigationBarHidden = YES;
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _layout.itemSize = CGSizeMake(CGRectGetWidth([UIScreen mainScreen].bounds), CGRectGetHeight([UIScreen mainScreen].bounds) - 49 - 64);
    _layout.minimumLineSpacing = 0;
    _layout.minimumInteritemSpacing = 0;
    _layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    kCollectionViewRegisterNib(@"PlayerCollectionViewCell", kPlayerCollectionViewCell);
    kCollectionViewRegisterNib(@"PlayerDetailCollectionViewCell", kPlayerDetailCollectionViewCell);
}
#pragma mark - collectionView 代理
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 2;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        PlayerCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kPlayerCollectionViewCell forIndexPath:indexPath];
        if (_record_plays) {
            cell.record_plays = _record_plays;
        }
        return cell;
    } else {
        PlayerDetailCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kPlayerDetailCollectionViewCell forIndexPath:indexPath];
        /**
         * ...
         */
        return cell;
    }
}
#pragma mark - 返回按钮点击事件
- (IBAction)backButtonClicked:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - 分享点击事件
- (IBAction)shareButtonClicked:(id)sender {
    NSLog(@"点击了分享按钮");
}
#pragma mark - 处理数据
- (void)handleData {
    NSString *url = [NSString stringWithFormat:@"http://api.kufm.cn/v3/playback/playpage/get_fm_comment?record_key=%ld&page_size=20&page_index=1", _record_plays.record[0].record_key];
    [GXNetTool GET:url andBody:nil andHeader:nil andResponse:GXJSON andSuccessBlock:^(id result) {
        
    } andFailureBlock:^(NSError *error) {
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
